var issubmit = true;
var isexist =true;

//校验函数
function checkText(formatResult, changeTarget, changeTarget2) {

	//alert(formatResult);
	if (formatResult) {
		
		if (changeTarget.css("display") != 'inline') {
			changeTarget.css("display", "inline");
		}
		if(arguments.length>3){
			changeTarget.html(arguments[3]);
		}
		changeTarget.css("color", "red");

		if (changeTarget2.css("display") != "none") {
			changeTarget2.css("display", "none");
		}
		//$(this).focus(); //获得焦点

		issubmit = false; //不能提交表单
	} else {
		//输入合法
		if (changeTarget.css("display") != "none") {
			changeTarget.css("display", "none");
		}
		if (changeTarget2.css("display") != "inline") {
			changeTarget2.children("img:first").attr("src",
			"../Images/dui.gif");
			changeTarget2.css("display", "inline");
		}
	}
}

///去掉字符串前尾的空格
function Trim(str){   
	return str.replace(/(\s*)|(\s*$)/g, "");   
} 

//验证表单函数
function checkform() {

	issubmit = true; //触发之前保证标志为true
	$(":input").blur(); //触发表单元素的blur事件
	return issubmit&&isexist;

}


//验证下拉框函数
function checkSelect(target){

	if ($(target).val() == "#") {
		if ($(target).next("span").children("img:first").attr(
		"src") != "../Images/cuo.gif") {
			$(target).next("span").children("img:first").attr(
					"src", "../Images/cuo.gif");
		}

		$(target).next("span").css("display", "inline"); //显示错误提示
		//$("#de").focus(); //继续获得焦点
		issubmit = false; //不能提交表单
	} else {
		if ($(target).next("span").children("img:first").attr(
		"src") != "../Images/dui.gif") {
			$(target).next("span").children("img:first").attr(
					"src", "../Images/dui.gif");
		}

		$(target).next("span").css("display", "inline"); //显示正确提示
	}

}

//校验文件框函数
function checkFile(target){
	//var fileSize = 0; //图片大小 
	var filePath = target.value;  
	var pos = filePath.lastIndexOf(".");
	var houzhui = filePath.substring(pos,filePath.length);
	//校验文件格式
	var flag=!isImage(houzhui.toLowerCase());
	checkText(flag,$(target).next('#fileTip'),$(target).nextAll('.normal'));
}


//判断图片格式是否合法
function isImage(image_){
	var _hou=['.doc','.docx','.xls','.ppt','.pdf','.wps','.txt'];   //定义支持文档的格式
	for(var i=0;i<_hou.length;i++){
		if(image_==_hou[i]){
			return true;
		}
	}
	return false;
}

